package huixue.cn.com.rxapp.ui;

import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import huixue.cn.com.rxapp.R;
import huixue.cn.com.rxapp.base.SimpleActivity;
import huixue.cn.com.rxapp.download.DownLoadFile;

public class DownloadActivity extends SimpleActivity {

    @BindView(R.id.btn_progress)
    Button btnProgress;
    private String loadUrl = "http://gdown.baidu.com/data/wisegame/d2fbbc8e64990454/wangyiyunyinle_87.apk";
    private String filePath = Environment.getExternalStorageDirectory() + "/" + "网易云音乐.apk";

    DownLoadFile downLoadFile;


    @Override
    public int getLayout() {
        return R.layout.activity_download;
    }

    @Override
    public void initView() {

    }

    @Override
    public void addEvent() {
        downLoadFile = new DownLoadFile(this,loadUrl, filePath, 3);
        downLoadFile.setOnDownLoadListener(new DownLoadFile.DownLoadListener() {
            @Override
            public void getProgress(int progress) {
                btnProgress.setText("当前进度 ："+progress+" %");
            }

            @Override
            public void onComplete() {
                Toast.makeText(DownloadActivity.this,"下载完成",Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onFailure() {
                Toast.makeText(DownloadActivity.this,"下载失败",Toast.LENGTH_SHORT).show();
            }
        });

        findViewById(R.id.bt).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                downLoadFile.downLoad();
            }
        });
        findViewById(R.id.bt_pause).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                downLoadFile.onPause();
            }
        });
        findViewById(R.id.bt_start).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                downLoadFile.onStart();
            }
        });
        findViewById(R.id.bt_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                downLoadFile.cancel();
            }
        });
    }



    /*@OnClick(R.id.btn_dw)
    public void onViewClicked() {
    }*/


    @Override
    protected void onDestroy() {
        downLoadFile.onDestroy();
        super.onDestroy();
    }
}
